package com.example.booksystem.listener;

import com.example.booksystem.bean.Type;
import com.example.booksystem.biz.TypeBiz;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

@WebListener
public class TypeServletContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //获取所有类型信息
        TypeBiz typeBiz = new TypeBiz();
        List<Type> types = typeBiz.getAll();
        //获取application对象
        ServletContext application = sce.getServletContext();
        //将信息存入application中
        application.setAttribute("types",types);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        ServletContextListener.super.contextDestroyed(sce);
    }
}
